package com.hr;

import java.io.Serializable;

import org.hibernate.type.Type;
import org.springframework.stereotype.Service;

import com.espirit.eap.manager.DefaultEntityInterceptor;
import com.espirit.finance.core.AcctTerm;
import com.googlecode.cswish.struts.spring.ObjectFactory;

@Service
public class HrEntityInteceptor extends DefaultEntityInterceptor{

	private static final long serialVersionUID = -3745003545920606327L;
	private HrSettingService hrSettingService;
	
	
	@Override
	public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState,
			String[] propertyNames, Type[] types) {
		boolean modified = super.onFlushDirty(entity, id, currentState, previousState, propertyNames, types);
		
		return modified;
	}
	
	@Override
	protected AcctTerm getAcctTerm() {
		return  getHrSettingService().getHrSetting().getCurrentAcctTerm();
	}
	
	protected HrSettingService getHrSettingService() {
		if (hrSettingService == null) {
			hrSettingService = ObjectFactory.getInstance().getBean(HrSettingService.class, true);
		}
		return hrSettingService;
	}
}
